package square;

import java.awt.image.BufferedImage;
import java.util.Objects;

/*
属性： 行，列，小方格的图片
方法：左移，右移，下落
*/
public class Cell {
    // 行
    private int row;
    //列
    private int col;
    //方格的图片
    private BufferedImage image;
    //带参的构造方法
    public Cell(int row, int col, BufferedImage image) {
        this.image = image;
        this.col = col;
        this.row = row;
    }

    //不带参的构造方法
    public Cell() {
    }
    //重写toString方法
    @Override
    public String toString() {
        return "Squar{"+
                "row"+ row +
                ", col=" + col +
                ",  image=" + image +
                '}';
    }
    //重写equals方法
    @Override
    public boolean equals(Object obj) {
       if(this == obj) return true;
       if(obj == null || getClass() != obj.getClass()) return false;
       Cell cell = (Cell)  obj;
       return row == cell.row && col == cell.col && Objects.equals(image, cell.image);
    }
    //重写hashCode方法
    @Override
    public int hashCode() {
        return Objects.hash(row,col,image);
    }

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public int getCol() {
        return col;
    }

    public void setCol(int col) {
        this.col = col;
    }
    //方块左移一格,就是让列减减
    public void left(){
        col--;
    }
    //方块右移一格，就是让列加加
    public  void right (){
        col++;
    }
    //方块下落一格，就是让行加加
    public  void drop(){
        row++;
    }

}
